<?php
namespace app\api\model;
use think\Model;
use think\model\concern\SoftDelete;

class CustomerConfig extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;
    protected $autoWriteTimestamp = true;
    protected $globalScope = ['shop_id'];
    public function scopeShop_id($query)
    {
        $query->where('shop_id', ShopId());
    }
    //字段列表
    public static function field_list()
    {
        $value = [
            [
                'id' => 'classify',
                'name' => '客户分类',
            ],
            [
                'id' => 'comefrom',
                'name' => '客户来源',
            ],
            [
                'id' => 'status',
                'name' => '客户状态',
            ],
        ];
        return $value;
    }
    
    public function getFieldAttr($value)
    {
        $name = ['classify'=>'客户分类','comefrom'=>'客户来源','status'=>'客户状态'];
        return $name[$value];
    }
    
    //统计分类数量
    public function countClassify()
    {
        return $this->hasMany(Customer::class,'classify','id');
    }
    
    //统计来源数量
    public function countComefrom()
    {
        return $this->hasMany(Customer::class,'comefrom','id');
    }
    //统计来源数量
    public function countStatus()
    {
        return $this->hasMany(Customer::class,'status','id');
    }
    
}